package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.hqfinance.domain.*;
import com.ruoyi.hqfinance.domain.vo.HqCollectPaiFeeByChannelVo;
import com.ruoyi.hqfinance.domain.vo.HqPaiFeeSubjectByPayVo;
import com.ruoyi.hqfinance.domain.vo.HqPaiFeeSubjectByReceiveVo;
import com.ruoyi.hqfinance.service.HqChannelService;
import com.ruoyi.hqfinance.service.HqCollectPaiFeeByChannelService;
import com.ruoyi.hqfinance.service.HqPaiFeeSubjectService;
import com.ruoyi.hqfinance.service.HqSettleSubjectService;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.utils.TableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/settleSynthesize")
@Api(tags = "总部财务-派费综合报表")
public class HqPaiFeeSynthesizeController {
    @Autowired
    private HqSettleSubjectService hqSettleSubjectService;
    @Autowired
    private HqChannelService hqChannelService;
    @Autowired
    private HqCollectPaiFeeByChannelService hqCollectPaiFeeByChannelService;
    @Autowired
    private HqPaiFeeSubjectService hqPaiFeeSubjectService;
    @Autowired
    private TableService tableService;

    @ApiOperation("结算科目下拉框")
    @GetMapping("/subject")
    public R selectSubject(){
        List<HqSettleSubject> settleSubjects = hqSettleSubjectService.selectAll();
        if (settleSubjects == null || settleSubjects.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(settleSubjects);
        }
    }

    @ApiOperation("渠道下拉框")
    @GetMapping("/channel")
    public R selectChannel(){
        List<HqChannel> channels = hqChannelService.selectAll();
        if (channels == null || channels.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(channels);
        }
    }

    @ApiOperation("费用子项汇总")
    @PostMapping("/collectPaiFeeByChannel")
    public R collectPaiFeeByChannel(@RequestBody HqCollectPaiFeeByChannelVo vo){
        if (vo != null){
            String startTime = vo.getStartTime().replace("-", "");
            String endTime = vo.getEndTime().replace("-", "");
            System.out.println(startTime);
            System.out.println(endTime);
            vo.setStartTime(startTime);
            vo.setEndTime(endTime);
        }
        List<HqCollectPaiFeeByChannel> list = hqCollectPaiFeeByChannelService.collectPaiFeeByChannel(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new HqCollectPaiFeeByChannel());
        return TableUtils.handleListResponse(list, fieldList, "暂无数据");
    }

    @ApiOperation("科目汇总")
    @PostMapping("/subject")
    public R subject(@RequestBody HqPaiFeeSubjectByReceiveVo vo){
        List<HqPaiFeeSubjectByReceive> list = hqPaiFeeSubjectService.paiFeeSubjectByDayByReceive(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new HqPaiFeeSubjectByReceive());
        return TableUtils.handleListResponse(list, fieldList, "暂无数据");
    }
}
